package com.kdg.thread.consurrenttest;

import java.util.concurrent.*;

/**
 * @author kdg
 * @description:
 * @date 2018/5/17.
 */
public class CallableTest implements Callable {

    private String name;

    public CallableTest(String name) {
        this.name = name;
    }

    @Override
    public Object call() throws Exception {
        StringBuffer str = new StringBuffer();
        for(int i=0;i<10;i++){
            str.append(name);
        }
        Thread.sleep(100);
        return str.toString();
    }

    public static void main(String[] args) throws InterruptedException, ExecutionException {
        CallableTest aaa = new CallableTest("aaa");
        FutureTask<String> tasks = new FutureTask<String>(aaa);
        ExecutorService executorService = Executors.newFixedThreadPool(1);
        executorService.submit(tasks);
        Thread.sleep(2000);
        System.out.println(tasks.get());
        executorService.shutdown();
    }
}
